-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow multiple (fixed-size) subslices borrows in one pattern #101
Conversation
+1, I was going to propose the same thing. If we allow runtime values for the lengths of the subslices, and add support for multiple (I'm not entirely sold on the syntax, but I think your idea is better than anything I came up with.) |
cc @jakub- |
-1. I think I'd actually be in favour of removing them altogether or reducing them to only the simplest cases ([a, b, c, ..tail]). |
To elaborate, they're making the pattern sanity check pass much more complicated than it really needs to be and add significant disconnect between that pass and the codegen for patterns. I think I'd also agree they also don't fit well with the other patterns that only cover ADTs, which vectors are not. |
Is it even possible to check exhaustiveness and redundancy of these kinds of patterns? |
I think it would have to be conservative, i.e. if the compiler can't prove exhaustiveness, require a wildcard pattern. |
@zwarich |
Sorry, I totally missed the fixed-size qualification. |
It depends on whether you allow the fixed sizes to be runtime values. If you do, my answer applies. If you don't, @krdln's does. I think. Edit: Hm, I see now that runtime values for the fixed sizes was never mentioned in the OP. Mea culpa. I misinterpreted the unresolved question section. |
FWIW, I think this syntax change makes some logical sense on its own terms. We currently use the syntax And then as a side benefit, it becomes possible to have both of them where the cases overlap, as with the fixed-length slice patterns in this proposal. |
+1 I like this. At the very least, I think we should change |
This was discussed at this week's Rust meeting (https://github.com/rust-lang/meeting-minutes/blob/master/weekly-meetings/2014-08-12.md). We decided that we don't want to implement these changes in full, in particular that enhancing slice matching is something we are a little bit uncomfortable with and needs some thought and planning but is low enough priority that we don't want to do that before 1.0. However, we are sympathetic to leaving this option open in the future, so we would like to make the change to slice syntax (the position of Thanks for the RFC! |
I'm happy to hear that there's a slight possibility that my RFC might be accepted in a far future! Edit: Here it is: #202 |
6357402
to
e0acdf4
Compare
Change syntax in slice pattern matching from
..xs
toxs..
(eg.[head, tail..]
),and allow multiple (fixed-size) subslices borrows in one pattern (eg.
[xs..3, ys..3]
).